#pragma once
#include "FishFactory.h"
#include "GoldFish.h"
#include "Salmon.h"

using namespace std;

const FishFactory::FISH_TYPE FishFactory::GOLD_FISH		=	1;
const FishFactory::FISH_TYPE FishFactory::SALMON		=	2;
/*
 add more predefined implementations here
*/

// CreateFish and CopyFish both throw a bad_alloc& exception
FishImpl * FishFactory::CreateFish(FISH_TYPE impl, const Point& speed, const Point& location, bool transparent, int size){
	switch (impl){

	case GOLD_FISH: {
		try{
			return new GoldFish(speed, location, transparent, size);
		}
		catch (bad_alloc& ba){
			throw;
		}
		break;
					}
	case SALMON: {
		try{
			return new Salmon(speed, location, transparent, size);
		}
		catch (bad_alloc& ba){
			throw;
		}
		break;
				 }
	default: {
		// unknown implementation - return 0
		return 0;
			 }

	}// end of switch
}

FishImpl * FishFactory::CopyFish(const FishImpl& fish){
	const FishImpl * fishPtr = &fish;
	
	// find the right rtti and run the right copy-ctor
	if (typeid(fish) == typeid(GoldFish)){
		try{
			return new GoldFish(*(const GoldFish *)fishPtr);
		}
		catch (bad_alloc& ba){
			throw;
		}
	}
	else if ( typeid(fish) == typeid(Salmon)){
		try{
			return new Salmon(*(const Salmon *)fishPtr);
		}
		catch (bad_alloc& ba){
			throw;
		}
	}
	else {
		// unknown implementation - return 0
		return 0;
	}
}